package com.mylibraryapplication.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.mylibrary.view.pickerView.OptionsPickerView;
import com.mylibraryapplication.R;
import com.mylibraryapplication.base.BaseActivity;
import com.mylibraryapplication.view.TitleView;

import java.util.ArrayList;
/**
 * @author yinsujun  Created at 2016/7/26 17:04
 * 3D滚轮
 */
public class TimePickerActivity extends BaseActivity {

    private TextView tvResult;
    private OptionsPickerView pickerView;
    private TitleView tvTitle;

    @Override
    public int getLayoutId() {
        return R.layout.activity_time_picker;
    }

    @Override
    public void initView() {
        tvResult= (TextView) findViewById(R.id.time_picker_tv_result);
        tvTitle= (TitleView) findViewById(R.id.title);
        tvTitle.setTitle("滚轮选择");
        setData();
        onClick();
    }
    private ArrayList<String> options1Items = new ArrayList<String>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<ArrayList<String>>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<ArrayList<ArrayList<String>>>();
    private void setData(){
        //选项1
        options1Items.add("广东");
        options1Items.add("湖南");

        //选项2
        ArrayList<String> options2Items_01=new ArrayList<String>();
        options2Items_01.add("广州");
        options2Items_01.add("佛山");
        options2Items_01.add("东莞");
        ArrayList<String> options2Items_02=new ArrayList<String>();
        options2Items_02.add("长沙");
        options2Items_02.add("岳阳");
        options2Items.add(options2Items_01);
        options2Items.add(options2Items_02);
        Log.e(TAG,options2Items.toString());

        //选项3
        ArrayList<ArrayList<String>> options3Items_01 = new ArrayList<ArrayList<String>>();
        ArrayList<ArrayList<String>> options3Items_02 = new ArrayList<ArrayList<String>>();
        ArrayList<String> options3Items_01_01=new ArrayList<String>();
        options3Items_01_01.add("白云");
        options3Items_01_01.add("天河");
        options3Items_01_01.add("海珠");
        options3Items_01_01.add("越秀");
        options3Items_01.add(options3Items_01_01);
        ArrayList<String> options3Items_01_02=new ArrayList<String>();
        options3Items_01_02.add("南海");
        options3Items_01.add(options3Items_01_02);
        ArrayList<String> options3Items_01_03=new ArrayList<String>();
        options3Items_01_03.add("常平");
        options3Items_01_03.add("虎门");
        options3Items_01.add(options3Items_01_03);

        ArrayList<String> options3Items_02_01=new ArrayList<String>();
        options3Items_02_01.add("长沙1");
        options3Items_02.add(options3Items_02_01);
        ArrayList<String> options3Items_02_02=new ArrayList<String>();
        options3Items_02_02.add("岳1");
        options3Items_02.add(options3Items_02_02);

        options3Items.add(options3Items_01);
        options3Items.add(options3Items_02);

        initPickerView();

    }

    @SuppressWarnings("unchecked")
    private OptionsPickerView initPickerView() {
        //选项选择器
        pickerView = new OptionsPickerView(this);
//        pickerView.setSubmitColor(ContextCompat.getColor(mContext,R.color.app_main_color));
        //一级
        Log.e(TAG,"省==="+options1Items.toString());
        Log.e(TAG,"市=="+options2Items.toString());

        pickerView.setPicker(options1Items,options2Items,true);
        pickerView.setTitle("城市");
        pickerView.setCyclic(false);
        //设置默认选中的三级项目
        //监听确定选择按钮
        pickerView.setSelectOptions(1);
        pickerView.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
               tvResult.setText(options1Items.get(options1)+"省"+options2Items.get(options1).get(option2)+"市"
                       +options3Items.get(options1).get(option2).get(options3)+"区");
            }
        });
        return pickerView;
    }

    private void onClick(){
        tvResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pickerView.isShowing()){
                    pickerView.dismiss();
                }else
                pickerView.show();
            }
        });
    }
}
